package com.example.project;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.project.service.MessageService;

public class MessagingActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.messaging);
		
		Button sendButton = (Button)findViewById(R.id.sendMessageButton);
		
		sendButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				EditText editMessageText = (EditText) findViewById(R.id.messageEdit);
				String message = editMessageText.getText().toString();
				
				// Call Message Service
				Intent messageService = new Intent(getBaseContext(), MessageService.class);
				messageService.putExtra("message", message);
				messageService.putExtra("address", getIntent().getStringExtra("address"));
				messageService.putExtra("port", getIntent().getStringExtra("port"));
				messageService.putExtra("token", getIntent().getStringExtra("token"));
				messageService.putExtra("exam", getIntent().getStringExtra("exam"));
				startService(messageService);
				
				// Refresh screen
				Toast.makeText(getBaseContext(), "Message sended", Toast.LENGTH_SHORT).show();
				editMessageText.setText("");
			}
		});
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return false;
	}
	
}
